"""Simple VANET mobility and neighbor simulation."""
from dataclasses import dataclass, field
from typing import List, Dict, Tuple
import math
import random

@dataclass
class Vehicle:
    id: int
    position: Tuple[float, float]
    velocity: Tuple[float, float]
    pseudonym: str
    heading: float = field(default=0.0)

    def step(self, dt: float = 1.0):
        # Slight random heading change
        self.heading += random.uniform(-0.1, 0.1)
        speed = math.hypot(*self.velocity)
        vx = speed * math.cos(self.heading)
        vy = speed * math.sin(self.heading)
        x, y = self.position
        self.position = (x + vx * dt, y + vy * dt)


def neighbors(vehicles: List[Vehicle], range_meters: float = 150.0) -> Dict[int, List[int]]:
    adj = {v.id: [] for v in vehicles}
    for i in range(len(vehicles)):
        for j in range(i+1, len(vehicles)):
            v1, v2 = vehicles[i], vehicles[j]
            dx = v1.position[0] - v2.position[0]
            dy = v1.position[1] - v2.position[1]
            d = math.hypot(dx, dy)
            if d <= range_meters:
                adj[v1.id].append(v2.id)
                adj[v2.id].append(v1.id)
    return adj


def simulate_step(vehicles: List[Vehicle], dt: float = 1.0):
    for v in vehicles:
        v.step(dt)
    return vehicles
